<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('修改banner')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-employee-add" th:object="${banner}">
        <input type="hidden" th:field="*{id}" name="id">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">标题：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="title" required th:field="*{title}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">图片：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" id="imageSrc" name="imageSrc"
                       th:value="*{imageSrc}">
                <img th:src="*{imageSrc}" width="50%" id="imgUrl">
                <br>
                <button type="button" class="imgBtn">浏览</button>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b" th:with="items=${@dict.getType('business_banner_type')}" >
                    <option th:each="item : ${items}" th:text="${item.label}"
                            th:value="${item.value}" th:field="*{type}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('business_data_state')}">
                    <input type="radio" th:id="${dict.id}" name="state" th:value="${dict.value}"
                           th:checked="${dict.isDefault}" th:field="*{state}">
                    <label th:for="${dict.id}" th:text="${dict.label}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">顺序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="sort" required th:field="*{sort}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">关联内容：</label>
            <div class="col-sm-8">
                <select name="contentId" class="form-control select2-hidden-accessible" data-select2-id="1"
                        tabindex="-1" aria-hidden="true" th:field="*{contentId}">
                    <option value="">--请选择关联内容--</option>
                    <option th:each="item : ${contents}" th:text="${item.goodsName}"
                            th:value="${item.id}"></option>
                </select>
            </div>
        </div>

    </form>
</div>
<th:block th:include="common/include :: footer"/>
<!-- 文件上传插件 -->
<link type="text/css" rel="stylesheet" href="/plugins/uploadifive/uploadifive.css"/>
<script type="text/javascript" src="/plugins/uploadifive/jquery.uploadifive.min.js"></script>
<!-- 富文本插件 -->
<script src="/plugins/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
        var prefix = ctx + "/business/banners";
        //表单提交验证
        $(function () {
            //图片上传
            $('.imgBtn').uploadifive({
                'auto': true,  //自动发起图片上传请求
                'uploadScript': '/business/upload',   //处理上传文件的请求路径
                'buttonClass': "btn-link",
                'fileObjName': 'file',   //上传文件参数名
                'buttonText': '浏览...',
                'fileType': 'image',
                'multi': false,
                'fileSizeLimit': 5242880,
                'removeCompleted': true, //取消上传完成提示
                'uploadLimit': 1,
                //'queueSizeLimit'  : 10,
                'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
                'onUploadComplete': function (file, data) {
                    let result = JSON.parse(data);
                    if (0 === result.code) {
                        $("#imgUrl").attr("src", result.url);
                        $("#imageSrc").val(result.url);
                        $.modal.msg("上传成功！");
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                onFallback: function () {
                    $.modal.alertError("该浏览器无法使用!");
                }
            });
        });

		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-employee-add').serialize());
	        }
	    }

</script>
</body>
</html>
